package com.yuxi.controller;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 线程池使用
 * Created by yuxi on 16/11/14.
 */
@RestController
@RequestMapping("/")
public class ThreadPoolController {
    @Autowired
    private ThreadPoolTaskExecutor executor;

    @ApiOperation("线程池使用")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "username", dataType = "String", required = true, value = "用户的姓名", defaultValue = "zhaojigang"),
            @ApiImplicitParam(paramType = "query", name = "password", dataType = "String", required = true, value = "用户的密码", defaultValue = "wangna")
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
    })
    @RequestMapping(value = "/threadpool", method = RequestMethod.POST)
    public String addUser(@RequestParam("username") final  String username,
                           @RequestParam("password") final String password) {
        executor.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(username+"===="+ password);
            }
        });
        return "ok";
    }

}

